<?php
	class BackupControl extends Control{

		//数据库备份配置视图
		function index(){
			$this->display();
		}
		//处理提交的数据库备份配置项
		function editConfig(){

			if(isset($_POST['backup_row'])){
				$config = var_export($_POST,true);
				$str = "<?php\nif(!defined(PATH_HD)) exit;\nreturn ".$config.";\n?>";
				if(@file_put_contents("./config/backup.php", $str)){
					go("bakData");
				}
			}
		}
		//执行数据备份
		function bakData(){
			$config = include "./config/bakup.php";
			Backup::backup(array(
				'url'=>'showBakData',
				'dir'=>'./backup/'.time(),
				'step_time'=>$config['backup_step_time'],
				'row'=>$config['backup_row']
				));
		}
		//执行数据库还原
		function recovery(){
			$dir = $_GET['dir'];
			p($dir);
			Backup::recovery(array(
				'dir'=>'./backup/'.$dir,
				"url" => "__success",
               	"step_time"=>0,
				));
		}
		//执行完数据库还原后跳转到的方法
		function __success(){
			$this->success("数据库还原成功！",'showBakData');
		}

		//显示备份后的数据文件到视图
		function showBakData(){
			$data = dir::tree('./backup');
			$bakData = array();
			foreach($data as $key=>$value){
				$bakData[$key]['name'] = $value['name'];
				$bakData[$key]['path'] = $value['path'];
			}
			$sortData = arsort($bakData);
			$this->assign("bakdata",$bakData);
			$this->display();
		}
	}
?>